home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / pmap_getport.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  3KB  |  102 lines

  1. /*
  2.  * $Id: pmap_getport.c,v 1.2 1993/11/10 02:11:57 jraja Exp $
  3.  *
  4.  * $Log: pmap_getport.c,v $
  5.  * Revision 1.2  1993/11/10  02:11:57  jraja
  6.  * Fixed includes (added the sys/param.h).
  7.  * Changed close() on sockets to CloseSocket() for AMITCP.
  8.  *
  9.  */
  10. /* @(#)pmap_getport.c    2.2 88/08/01 4.0 RPCSRC */
  11. /*
  12.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  13.  * unrestricted use provided that this legend is included on all tape
  14.  * media and as a part of the software program in whole or part.  Users
  15.  * may copy or modify Sun RPC without charge, but are not authorized
  16.  * to license or distribute it to anyone else except as part of a product or
  17.  * program developed by the user.
  18.  * 
  19.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  20.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  21.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  22.  * 
  23.  * Sun RPC is provided with no support and without any obligation on the
  24.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  25.  * modification or enhancement.
  26.  * 
  27.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  28.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  29.  * OR ANY PART THEREOF.
  30.  * 
  31.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  32.  * or profits or other special, indirect and consequential damages, even if
  33.  * Sun has been advised of the possibility of such damages.
  34.  * 
  35.  * Sun Microsystems, Inc.
  36.  * 2550 Garcia Avenue
  37.  * Mountain View, California  94043
  38.  */
  39. #if !defined(lint) && defined(SCCSIDS)
  40. static char sccsid[] = "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
  41. #endif
  42.  
  43. /*
  44.  * pmap_getport.c
  45.  * Client interface to pmap rpc service.
  46.  *
  47.  * Copyright (C) 1984, Sun Microsystems, Inc.
  48.  */
  49.  
  50. #include <sys/param.h>
  51. #include <rpc/rpc.h>
  52. #include <rpc/pmap_prot.h>
  53. #include <rpc/pmap_clnt.h>
  54. #include <sys/socket.h>
  55. #include <net/if.h>
  56.  
  57. static struct timeval timeout = { 5, 0 };
  58. static struct timeval tottimeout = { 60, 0 };
  59.  
  60. /*
  61.  * Find the mapped port for program,version.
  62.  * Calls the pmap service remotely to do the lookup.
  63.  * Returns 0 if no map exists.
  64.  */
  65. u_short
  66. pmap_getport(address, program, version, protocol)
  67.     struct sockaddr_in *address;
  68.     u_long program;
  69.     u_long version;
  70.     u_int protocol;
  71. {
  72.     u_short port = 0;
  73.     int socket = -1;
  74.     register CLIENT *client;
  75.     struct pmap parms;
  76.  
  77.     address->sin_port = htons(PMAPPORT);
  78.     client = clntudp_bufcreate(address, PMAPPROG,
  79.         PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
  80.     if (client != (CLIENT *)NULL) {
  81.         parms.pm_prog = program;
  82.         parms.pm_vers = version;
  83.         parms.pm_prot = protocol;
  84.         parms.pm_port = 0;  /* not needed or used */
  85.         if (CLNT_CALL(client, PMAPPROC_GETPORT, xdr_pmap, &parms,
  86.             xdr_u_short, &port, tottimeout) != RPC_SUCCESS){
  87.             rpc_createerr.cf_stat = RPC_PMAPFAILURE;
  88.             clnt_geterr(client, &rpc_createerr.cf_error);
  89.         } else if (port == 0) {
  90.             rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
  91.         }
  92.         CLNT_DESTROY(client);
  93.     }
  94. #ifdef AMITCP
  95.     (void)CloseSocket(socket);
  96. #else
  97.     (void)close(socket);
  98. #endif
  99.     address->sin_port = 0;
  100.     return (port);
  101. }
  102.